package cn.stylefeng.guns.sys.modular.system.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum;
import cn.stylefeng.guns.sys.core.log.LogObjectHolder;
import cn.stylefeng.guns.sys.modular.system.db4.service.TeamService;
import cn.stylefeng.guns.sys.modular.system.entity.*;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.ProjectTaskEnum;
import cn.stylefeng.guns.sys.modular.system.entity.Enum.RoleIdEnum;
import cn.stylefeng.guns.sys.modular.system.mapper.ProjectMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.ProjectParam;
import cn.stylefeng.guns.sys.modular.system.model.result.ProjectResult;
import cn.stylefeng.guns.sys.modular.system.service.MdzxService;
import cn.stylefeng.guns.sys.modular.system.service.ProjectService;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 控制器
 *
 * @author jiangge
 * @Date 2020-09-10 21:46:43
 */
@Controller
@RequestMapping("/project")
public class ProjectController extends BaseController {

    private String PREFIX = "/modular/system/project/";

    @Autowired
    private ProjectService projectService;
    @Autowired
    private UserService userService;
    @Autowired
    private TeamService teamService;
    @Resource
    private MdzxService mdzxService;
    @Autowired
    private ProjectMapper projectMapper;

    /**
     * 跳转到主页面
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("")
    public String index(Model model,Integer pageA) {
        User user = this.userService.getById(LoginContextHolder.getContext().getUserId());
        model.addAttribute("roleids", user.getRoleId());
        model.addAttribute("pageA", pageA);
        //开发总监
        model.addAttribute("role_kfzj", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_KFZJ.getCode()));
        //开发区域经理
        model.addAttribute("role_kfqyjl", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_KFQYJL.getCode()));
        //工程总监
        model.addAttribute("role_gczj", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_GCZJ.getCode()));
        //营运总监
        model.addAttribute("role_yyzj", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_YYZJ.getCode()));
        //开发人员
        model.addAttribute("role_kfry", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_KFRY.getCode()));
        //营运经理
        model.addAttribute("role_yyjl", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_YYJL.getCode()));
        //督导
        model.addAttribute("role_dd", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_DD.getCode()));
        //网上建店负责人
        model.addAttribute("role_netshop", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_NETSHOP.getCode()));
        model.addAttribute("role_gcb", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_GCB.getCode()));//
        return PREFIX + "project.html";
    }

    /**
     * 跳转到主页面
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/adminPage")
    public String adminPage(Model model,Integer pageA) {
        User user = this.userService.getById(LoginContextHolder.getContext().getUserId());
        model.addAttribute("roleids", user.getRoleId());
        model.addAttribute("pageA", pageA);
        //开发总监
        model.addAttribute("role_kfzj", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_KFZJ.getCode()));
        //工程总监
        model.addAttribute("role_gczj", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_GCZJ.getCode()));
        //营运总监
        model.addAttribute("role_yyzj", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_YYZJ.getCode()));
        //开发人员
        model.addAttribute("role_kfry", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_KFRY.getCode()));
        //营运经理
        model.addAttribute("role_yyjl", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_YYJL.getCode()));
        //督导
        model.addAttribute("role_dd", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_DD.getCode()));
        //网上建店负责人
        model.addAttribute("role_netshop", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_NETSHOP.getCode()));
        model.addAttribute("role_gcb", judgeRole(user.getRoleId(), RoleIdEnum.ROLE_GCB.getCode()));//
        return PREFIX + "project_admin.html";
    }

    /**
     * 跳转到营运总监查看工程列表-菜单：营运查询
     * @author liuy
     * @Date 2021-03-19
     */
    @RequestMapping("/projectZJ")
    public String projectZJ() {
        return PREFIX + "projectZJ.html";
    }

    /**
     * 可乐机报表页面
     */
    @RequestMapping("/projectCokeReport")
    public String projectCokeRrport() {
        return PREFIX + "projectCokeReport.html";
    }

    /**
     * 跳转到开业查询页面-菜单：开业查询
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/projectKY")
    public String projectKY() {
        return PREFIX + "projectKY.html";
    }


    private boolean judgeRole(String roleIds, Long roleId) {
        return roleIds.contains(roleId.toString());
    }

    /**
     * 编辑页面
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "project_edit.html";
    }

    /**
     * 填表页面(商务)
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/things")
    public String things(Integer id, String swedit, String auditbtn, ModelMap map) {
        map.put("id", id);
        map.put("swedit", swedit);
        map.put("auditbtn", auditbtn);
        map.put("list", selectMsgList(id, 36));
        return PREFIX + "project_things.html";
    }

    /**
     * 填表页面(商务条件最新)
     */
    @RequestMapping("/swtj")
    public String swtj(Integer id, String swedit, String auditbtn, ModelMap map) {
        String  kfqyjl="1";
        String  kfry="1";
        String  flag="1";
        List<String> roleNames = LoginContextHolder.getContext().getUser().getRoleNames();
        if(roleNames.contains("营运总监")){
            auditbtn="0";
        }
        if(roleNames.contains("开发区域经理")){
            kfqyjl="2";
        }
        if(roleNames.contains("工程开发人员")&&!roleNames.contains("全国")){
            kfry="2";
        }
        if(roleNames.contains("工程开发人员")&&roleNames.contains("全国")){
            flag="2";
        }
        if(roleNames.contains("工程开发人员")&&roleNames.contains("开发区域经理")){
            flag="3";
        }
        map.put("id", id);
        map.put("swedit", swedit);
        map.put("auditbtn", auditbtn);
        map.put("kfqyjl", kfqyjl);
        map.put("kfry", kfry);
        map.put("flag", flag);
        map.put("list", selectMsgList(id, 36));
        return PREFIX + "project_swtj.html";
    }

    /**
     * 商务条件详情
     */
    @RequestMapping("/detailList")
    @ResponseBody
    public ResponseData swtjList(Integer id, String swedit, String auditbtn, ModelMap map) {
        List<String> roleNames = LoginContextHolder.getContext().getUser().getRoleNames();
        if(roleNames.contains("营运总监")){
            auditbtn="0";
        }
        map.put("id", id);
        map.put("swedit", swedit);
        map.put("auditbtn", auditbtn);
        map.put("list", selectMsgLists(id, 36));
       return  ResponseData.success(map);
    }
    /**
     * 填表页面(商务)
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/thingsNew")
    public String thingsNew(Integer id, String swedit, String auditbtn, ModelMap map) {
        map.put("id", id);
        map.put("swedit", swedit);
        map.put("auditbtn", auditbtn);
        map.put("list", selectMsgList(id, 36));
        return PREFIX + "project_thingsNew.html";
    }
    /**
     * 填表页面(商务)
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/shangwu")
    public String shangwu(Integer id, String swedit, String auditbtn, ModelMap map) {
        map.put("id", id);
        map.put("swedit", swedit);
        map.put("auditbtn", auditbtn);
        map.put("list", selectMsgList(id, 36));
        return PREFIX + "project_shangwu.html";
    }
    /**
     * 填表页面(商务)
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/adminThings")
    public String adminThings(Integer id, String swedit, String auditbtn, ModelMap map) {
        map.put("id", id);
        map.put("swedit", swedit);
        map.put("auditbtn", auditbtn);
        map.put("list", selectMsgList(id, 36));
        return PREFIX + "project_admin_things.html";
    }

    /**
     * 填表页面（工程）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/projectTerm")
    public String projectTerm(Integer id,Integer pageA, String gcedit, String auditbtn,String auditbtn1, ModelMap map) {
        map.put("id", id);
        map.put("gcedit", gcedit);
        map.put("auditbtn", auditbtn);
        map.put("auditbtn1", auditbtn1);
        map.put("pageA", pageA);
        map.put("list", selectMsgList(id, 38));
        return PREFIX + "project_Term.html";
    }
    /**
     * 填表页面（工程）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/projectAdminTerm")
    public String adminProjectTerm(Integer id,Integer pageA, String gcedit, String auditbtn, ModelMap map) {
        map.put("id", id);
        map.put("gcedit", gcedit);
        map.put("auditbtn", auditbtn);
        map.put("pageA", pageA);
        map.put("list", selectMsgList(id, 38));
        return PREFIX + "project_admin_Term.html";
    }

    /**
     * 填表页面（网上建店）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/internetStore")
    public String internetStore(Integer id, Integer role, String content, Integer qb, ModelMap map) {
        map.put("id", id);
        map.put("qb", qb);
        map.put("role", role);
        map.put("content", content);
        map.put("list", selectMsgList(id, 34));
        return PREFIX + "project_internetStore.html";
    }

    /**
     * 填表页面（线上套餐）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/surfMeal")
    public String surfMeal(Integer id, Integer role, String content, Integer qb, ModelMap map) {
        map.put("id", id);
        map.put("qb", qb);
        map.put("role", role);
        map.put("content", content);
        map.put("list", selectMsgList(id, 35));
        return PREFIX + "project_surfMeal.html";
    }

    /**
     * 填表页面（排队机）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/queuing")
    public String queuing(Integer id, Integer role, String content, Integer qb, ModelMap map) {
        map.put("id", id);
        map.put("qb", qb);
        map.put("role", role);
        map.put("content", content);
        map.put("list", selectMsgList(id, 37));
        return PREFIX + "project_queuing.html";
    }

    /**
     * 填表页面（现场踏勘）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/premises")
    public String premises(Integer id, ModelMap map) {
        map.put("id", id);
        map.put("list", selectMsgList(id, 39));
        return PREFIX + "project_premises.html";
    }
    /**
     * 填表页面（现场踏勘）
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/adminPremises")
    public String adminPremises(Integer id, ModelMap map) {
        map.put("id", id);
        map.put("list", selectMsgList(id, ProjectTaskEnum.TASK_39.getCode()));
        return PREFIX + "project_admin_premises.html";
    }

    /**
     * 指定营运经理页面
     */
    @RequestMapping("/zdyyjl")
    public String zdyyjl(String phone, ModelMap map) {
        map.put("phone", phone);
        return PREFIX + "selectYyjl.html";
    }

    /**
     * 新增工程
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(ProjectParam projectParam) {
        //判断工程名是否重复
//        String projectName = new StringBuilder(projectParam.getProvinceName()).append(projectParam.getCityName()).append(projectParam.getName()).toString();
        String projectName = projectParam.getName();

        Project project = projectService.getOne(new QueryWrapper<Project>().eq("name", projectName));
        if (ToolUtil.isNotEmpty(project)) {
            return ResponseData.error(1, "店名有重复，可能在此地区已有门店，请尝试在商超/标志性地标前加路名");
        }
        this.projectService.add(projectParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(ProjectParam projectParam) {
        if(ToolUtil.isNotEmpty(projectParam.getYaoma())){
            boolean b = projectService.yaomaExist(projectParam);
            if(b){
                return ResponseData.error("妖码已存在");
            }
        }
        this.projectService.update(projectParam);
        return ResponseData.success();
    }

    /**
     * 批量隐藏接口
     */
    @RequestMapping("/editBatch")
    @ResponseBody
    public ResponseData editBatch(String ids, Integer status) {
        String id[] = ids.split(",");
        for (int i = 0; i < id.length; i++) {
            this.projectService.editBatch(id[i], status);
        }
        for (String s : id) {
            Project project=projectService.getById(s);
            if(ToolUtil.isNotEmpty(project)){
                if(ToolUtil.isNotEmpty(project.getYaoma())){
                    String yaoma=project.getYaoma();
                    //根据妖码更新门店装修的状态
                    Mdzx mdzx=mdzxService.getOne(new QueryWrapper<Mdzx>().eq("md_bianma",yaoma));
                    if(ToolUtil.isNotEmpty(mdzx)){
                        if(status==0){
                            mdzx.setStatusView("close");
                        }else if(status==1){
                            mdzx.setStatusView("open");
                        }
                        mdzxService.updateById(mdzx);
                    }
                }
            }
        }
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(ProjectParam projectParam) {
        this.projectService.removeById(projectParam.getId());
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(ProjectParam projectParam) {
        Project detail = this.projectService.getById(projectParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(ProjectParam projectParam) throws Exception {
        if(ToolUtil.isEmpty(projectParam.getAllStautusEnd())){
            projectParam.setAllStautusEnd("N");
        }
        return this.projectService.findPageBySpec(projectParam);
    }


    /**
     * 查询列表
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @ResponseBody
    @RequestMapping("/adminList")
    public LayuiPageInfo adminList(ProjectParam projectParam) throws Exception {
        if(ToolUtil.isEmpty(projectParam.getAllStautusEnd())){
            projectParam.setAllStautusEnd("N");
        }
        return this.projectService.adminList(projectParam);
    }


    /**
     * 跳到添加 工程/商务页面
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/jump")
    public String jump(String typeCode) {
        if ("GC_COND".equals(typeCode)) {
            return PREFIX + "project_gctj.html";
        } else if ("BUSY_COND".equals(typeCode)) {
            return PREFIX + "project_swtj.html";
        }
        return "";
    }


    /**
     * 修改档案
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:06 PM
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Project project) {
        if (ToolUtil.isOneEmpty(project, project.getId())) {
            throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
        }
        int value = this.projectService.getName(project.getName());
        if(value > 0){
            return false;
        } else {
            this.projectService.updateById(project);
            return SUCCESS_TIP;
        }
    }

    /**
     * 工程营运经理保存
     *
     * @param
     * @return
     * @author gyz
     * @date 2020/9/18 16:39:01
     */
    @RequestMapping("/saveGcyyjl")
    @ResponseBody
    public ResponseData saveGcyyjl(ProjectParam record) {
        projectService.saveGcyyjl(record);
        return ResponseData.success();
    }
    /**
     * 工程营运经理保存
     *
     * @param
     * @return
     * @author gyz
     * @date 2020/9/18 16:39:01
     */
    @RequestMapping("/saveGcyyjlAdmin")
    @ResponseBody
    public ResponseData saveGcyyjlAdmin(ProjectParam record) {
        projectService.saveGcyyjlAdmin(record);
        return ResponseData.success();
    }

    /**
     * 工程督导保存
     *
     * @param
     * @return
     * @author gyz
     * @date 2020/9/18 16:39:01
     */
    @RequestMapping("/saveGcDd")
    @ResponseBody
    public ResponseData saveGcDd(ProjectParam record) {
        projectService.saveGcDd(record);
        return ResponseData.success();
    }

    /**
     * 查询微信推送督导及营运经理
     *
     * @param proid
     * @return
     */
    @GetMapping("selectDd")
    public ResponseData selectDd(Integer proid) {
        projectService.selectDd(proid);
        return ResponseData.success();
    }

    /**
     * 查询督导列表
     *
     * @return
     */
    @RequestMapping(value = "/selectDdList")
    @ResponseBody
    public List<Map> selectDdList(String phone) {
//        return projectService.selectDdList(phone);
        return teamService.selectDdList(phone);
    }

    /**
     * 查询营运经理列表
     *
     * @return
     */
    @RequestMapping(value = "/selectYyjlList")
    @ResponseBody
    public List<Map> selectYyjlList() {
//        List<Map> maps = projectService.selectYyjlList();
        List<Map> maps = teamService.selectYyjlList();
        return maps;
    }

    /**
     * 查询需填表格列表
     */
    public String selectMsgList(Integer proId, Integer mouldId) {
        ArrayList<MouldBoardMsg> taskStatuses = (ArrayList) projectService.selectMsgList(proId, mouldId);
        String listJson = JSONArray.toJSONString(new ArrayList[]{taskStatuses});
        System.out.println("listJson:"+listJson);
        return listJson;
    }

    public List<MouldBoardMsg>selectMsgLists(Integer proId, Integer mouldId) {
        ArrayList<MouldBoardMsg> taskStatuses = (ArrayList) projectService.selectMsgList(proId, mouldId);
        System.out.println("list:"+taskStatuses);
        return taskStatuses;
    }

    /**
     * 跳转到工程流程图界面
     *
     * @author jiangge
     * @Date 2020-09-10
     */
    @RequestMapping("/projectFlow")
    public String projectFlow() {
        return PREFIX + "project_flow.html";
    }

    /**
     * 编辑页面
     *
     * @author jiangge
     * @Date 2020-09-15
     */
    @RequestMapping("/proFlowChart")
    public String proFlowChart() {
        return PREFIX + "proFlowChart.html";
    }

    /**
     * 工程完工
     *
     * @param proId
     * @return
     */
    public ResponseData status(Integer proId) {
        projectService.getStatus(proId);
        return ResponseData.success();
    }

    /**
     * 工程任务流水
     *
     * @param projectParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/proTaskFolwList")
    public LayuiPageInfo getAllProPageWithTaskFlow(ProjectParam projectParam) {
        return this.projectService.getAllProPageWithTaskFlow(projectParam);
    }

    /**
     * 所有工程任务
     *
     * @param projectParam
     * @return
     */
    @ResponseBody
    @RequestMapping("/allProject")
    public LayuiPageInfo getAllProject(ProjectParam projectParam) {
        return this.projectService.getAllProject(projectParam);
    }

    @ResponseBody
    @RequestMapping("/allProjectList")
    public ResponseData customMapList(ProjectParam projectParam) {
        List<Map<String, Object>> maps = this.projectService.customMapList(projectParam);
        return ResponseData.success(maps);
    }

    @ResponseBody
    @RequestMapping("/selectOneByParam")
    public ResponseData selectOneByParam(ProjectParam projectParam) {
        ProjectResult result = this.projectService.selectOneByParam(projectParam);
        return ResponseData.success(result);
    }

    @RequestMapping("/progress")
    public String progress() {
        return PREFIX + "project_progress.html";
    }

    @RequestMapping("/jindu")
    @ResponseBody
    public LayuiPageInfo jindu(ProjectParam param) {
        return projectService.jindu(param);
    }

    /**
     * 可乐机报表-查询列表
     * @param param
     * @return
     */
    @RequestMapping("/cokeReportList")
    @ResponseBody
    public LayuiPageInfo cokeReportList(ProjectParam param) {
        return projectService.cokeReportList(param);
    }

    @RequestMapping("/jinduExport")
    public ResponseEntity<byte[]> exportExcel(HttpServletRequest request, HttpServletResponse response, ProjectParam param) {
        return this.projectService.jinduExport(request, response,param);
    }

    @RequestMapping(value = "/getAreaByType")
    @ResponseBody
    public List<Area> getAreaByType() {
        List<Area> areaList = this.projectService.getAreaByType();
        return areaList;
    }


    /**
     * 地区统计
     * 补充：访问地址
     * @author zwf
     * @Date 2021-04-01
     */
    @RequestMapping("/projectDiquTongji")
    public String projectDiquTongji() {
        return PREFIX + "projectList.html";
    }
    @ResponseBody
    @RequestMapping("/projectList")
    public LayuiPageInfo projectList(ProjectParam projectParam) {
        return this.projectService.projectList(projectParam);
    }


    /**
     * 收银系统报表
     * @param
     * @return
     */
    @RequestMapping("/syxt")
    public String syxt() {
        return PREFIX + "syxt.html";
    }

    @ResponseBody
    @RequestMapping("/sYList")
    public LayuiPageInfo sYList(ProjectParam param) {
        return this.projectService.sYList(param);
    }


    @RequestMapping("/wsjdReport")
    public String wsjdReport() {
        return PREFIX + "project_wsjdReport.html";
    }

    @RequestMapping("/wsjdReportList")
    @ResponseBody
    public LayuiPageInfo wsjdReportList(ProjectParam param) {
        return projectService.wsjdReportList(param);
    }

    /**
     * 查询督导列表-all
     *
     * @return
     */
    @RequestMapping(value = "/selectDdListAll")
    @ResponseBody
    public List<Map> selectDdListAll() {
        return projectService.selectDdListAll();
    }

    /**
     * 查询店长列表-all
     *
     * @return
     */
    @RequestMapping(value = "/selectDzListAll")
    @ResponseBody
    public List<Map> selectDzListAll() {
        return projectService.selectDzListAll();
    }

    @RequestMapping("/finishList")
    public String finishList(Model model) {
        return PREFIX + "project_finishList.html";
    }

    @RequestMapping("/shanxiList")
    public String shanxiList(Model model) {
        return PREFIX + "project_shanxi.html";
    }

    @ResponseBody
    @RequestMapping("/listFinish")
    public LayuiPageInfo listFinish(ProjectParam projectParam) throws Exception {
        return this.projectService.listFinish(projectParam);
    }

    @RequestMapping("/finishAdd")
    public String finishAdd(ProjectParam param) {
       return PREFIX + "project_finishAdd.html";
    }

    @RequestMapping("/shanxiAdd")
    public String shanxiAdd(ProjectParam param) {
        return PREFIX + "project_shanxiAdd.html";
    }

    @RequestMapping("/addFinishItem")
    @ResponseBody
    public ResponseData addFinishItem(ProjectParam param) {
        return this.projectService.addFinishItem(param);
    }

    @RequestMapping("/addFinishSx")
    @ResponseBody
    public ResponseData addFinishSx(ProjectParam param) {
        return this.projectService.addFinishSx(param);
    }

    @RequestMapping("/areaSummaryExport")
    public ResponseEntity<byte[]> areaSummaryExport(HttpServletRequest request, HttpServletResponse response, ProjectParam param) {
        return this.projectService.areaSummaryExport(request, response,param);
    }

    @RequestMapping("/yaoma")
    public String yaoma(ProjectParam param) {
        return PREFIX + "project_yaoma.html";
    }

    @RequestMapping("/yaomaList")
    @ResponseBody
    public LayuiPageInfo yaomaList(ProjectParam param) {
        return projectService.yaomaList(param);
    }

    @RequestMapping("/yaomaListExport")
    public ResponseEntity<byte[]> yaomaListExport(HttpServletRequest request, HttpServletResponse response, ProjectParam param) {
        return this.projectService.yaomaListExport(request, response,param);
    }

    @RequestMapping("/yaomaManage")
    public String yaomaManage(ProjectParam param) {
        return PREFIX + "project_yaomaManage.html";
    }
    @RequestMapping("/wsjdAudit")
    public String wsjdAudit(ProjectParam param) {
        return PREFIX + "project_wsjdAudit.html";
    }

    /**
     * 工程未进场
     * @return
     */
    @RequestMapping("/projectWjc")
    public String projectWjc() {
        return PREFIX + "project_wjc.html";
    }

    /**
     * 工程未进场列表
     * @param param
     * @return
     */
    @RequestMapping("/projectWjcList")
    @ResponseBody
    public LayuiPageInfo projectWjcList(ProjectParam param) {
        return projectService.projectWjcList(param);
    }

    /**
     * 工程未进场列表
     * @param
     * @return
     */
    @RequestMapping("/wjcList")
    @ResponseBody
    public Object wjcList() {
        return projectService.wjcList();
    }


    /**
     * 跳转确认店名页面
     */
    @RequestMapping("/confirmName")
    public String confirmName() {
        return PREFIX + "project_confirmName.html";
    }

    /**
     * 确认店名列表
     */
    @RequestMapping("/confirmList")
    @ResponseBody
    public LayuiPageInfo confirmList(ProjectParam param) {
        return projectService.confirmList(param);
    }

    /**
     * 跳转确认店名修改页面
     */
    @RequestMapping("/confirmEdit/{id}")
    public String confirmEdit(@PathVariable Long id, Model model) {
        Project project = this.projectService.getById(id);
        model.addAllAttributes(BeanUtil.beanToMap(project));
        LogObjectHolder.me().set(project);
        return PREFIX + "confirm_edit.html";
    }

    /**
     * 跳转确认店名修改
     */
    @RequestMapping("/confirmUpdate")
    @ResponseBody
    public ResponseData confirmUpdate(Project project) {
        projectService.updateById(project);
        return ResponseData.success();
    }

    /**
     * 根据project_id同步店名
     */
    @RequestMapping("/syncDm")
    @ResponseBody
    public ResponseData syncDm(Integer id, String name, String yaoma) {

        //根据project_id更新门店装修的状态
        Mdzx mdzx = mdzxService.getOne(new QueryWrapper<Mdzx>().eq("bty_brand_id", id));
        if(ToolUtil.isNotEmpty(mdzx)){
            mdzx.setBtyBrandIdView(name);
            mdzx.setMdBianma(yaoma);
            mdzxService.updateById(mdzx);
        }

        Project project = new Project();
        project.setId(id);
        project.setDmSta(1);//是否确认店名状态；0->未确认，1->已确认
        //修改project表状态
        this.projectService.updateById(project);

        return ResponseData.success();
    }


    /**
     * 根据project_id批量同步店名
     */
    @RequestMapping("/syncDmBatch")
    @ResponseBody
    public ResponseData syncDmBatch(String ids) {

        String[] strArray = ids.split(",");
        List<String> idList = Arrays.asList(strArray);

        //根据project_id更新门店装修的状态
        List<Mdzx> mdzxList = mdzxService.list(new QueryWrapper<Mdzx>().in("bty_brand_id", idList));
        List<Project> proList = projectService.list(new QueryWrapper<Project>().in("id", idList));
        if (ToolUtil.isNotEmpty(proList)){
            Map<Object, Project> map = proList.stream().collect(Collectors.toMap(s -> s.getId(), s -> s));

            if(ToolUtil.isNotEmpty(mdzxList)){
                for (Mdzx mdzx : mdzxList) {
                    mdzx.setBtyBrandIdView(map.get(mdzx.getBtyBrandId()).getName());
                    mdzx.setMdBianma(map.get(mdzx.getBtyBrandId()).getYaoma());
                    mdzxService.updateById(mdzx);
                }
            }
        }

        //修改project表状态为已确认
        projectMapper.updateDmSta(proList);

        return ResponseData.success();
    }

    /**
     * 跳转收银建店页面
     */
    @RequestMapping("/syShop")
    public String syShop() {
        return PREFIX + "project_syShop.html";
    }

    /**
     * 收银建店列表
     */
    @RequestMapping("/syShopList")
    @ResponseBody
    public LayuiPageInfo syShopList(ProjectParam param) {
        return projectService.syShopList(param);
    }


    /**
     * 查询开发区域经理列表
     *
     * @return
     */
    @RequestMapping(value = "/qyjlList")
    @ResponseBody
    public List<Map> qyjlList() {
        List<Map> maps = projectService.qyjlList();
        return maps;
    }


}


